﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentsTagger.UI.ViewModel;
using DocumentsTagger.UI.Model;

namespace DocumentsTagger.UI.Commands
{
    class AddDeclinedTagToDocumentCommand:ACommandBase
    {
        private DocumentViewModel m_vm;

        public AddDeclinedTagToDocumentCommand(DocumentViewModel documentViewModel)
        {
            this.m_vm = documentViewModel;
        }

        /// <summary>
        /// returns the ability to execute the command
        /// </summary>
        /// <param name="parameter">The string of the tag to be added to declined tags list.</param>
        /// <returns>true if the command can be executed</returns>
        public override bool CanExecute(object parameter)
        {
            bool exists = false;
            foreach (TagUIModel item in m_vm.DeclinedTags)
            {
                if (item.Name == (string)parameter)
                {
                    exists = true;
                    break;
                }
            }
            return !exists;
        }

        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="parameter">The string of the tag to be added to declined tags list.</param>
        public override void Execute(object parameter) 
        {
            this.m_vm.AddDeclinedTagToDocument((string)parameter);
        }
    }
}
